<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport"
			content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="../../css/header.css" />
	</head>

	<body>

		<header class="mui-bar mui-bar-nav title">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left" style="color: white;"></a>
			<h1 class="mui-title title-color">学生预约申请审批</h1>
		</header>

		<div class="mui-content">

			<ul class="mui-table-view" id="ul_enterprise_list" style="margin-bottom: 10px;">
				<!-- <li class="btnOper mui-table-view-cell mui-media">
					<a href="javascript:;">
						<img class="mui-media-object mui-pull-left" src="../../images/1.jpg">
						<span id="span_nickname" class="mui-pull-right">
							<button type="button" class="notPassRequest mui-btn mui-btn-danger"
								style="padding: 4px 10px;margin-right: 5px;">不通过</button>
							<button type="button" class="passRequest mui-btn mui-btn-green"
								style="padding: 4px 10px;">通过</button>
						</span>
						<div class="mui-media-body">
							<label>学生:XXX</label>
							<p class="mui-ellipsis">申请公司:XXXXX</p>
						</div>
					</a>
				</li> -->
			</ul>

		</div>

		<script src="../../js/mui.min.js"></script>
		<script src="../../js/app.js"></script>
		<script type="text/javascript">
			mui.init();

			mui.plusReady(function() {
				var user = app.getGlobalUserInfo();

				// 加载教师得到班级学生的实习预约申请记录
				loadingOnlineApply();

			});

			// 加载教师得到班级学生的实习预约申请记录
			function loadingOnlineApply() {

				var teacher = app.getGlobalUserInfo();

				mui.ajax(app.serverUrl + "/user/teacher/examine_online_apply_list?user_id=" + teacher.user_id, {
					data: {},
					dataType: 'json', //服务器返回json格式数据
					type: 'post', //HTTP请求类型
					timeout: 10000, //超时时间设置为10秒；
					headers: {
						'Content-Type': 'application/json'
					},
					success: function(data) {
						if (data.status == 200) {
							var studentApplicationList = data.data;
							
							var ul_enterprise_list = document.getElementById("ul_enterprise_list");
							
							if (studentApplicationList != null && studentApplicationList.length > 0) {
								var apply_list_html = "";
								for (var i = 0; i < studentApplicationList.length; i++) {
									if (studentApplicationList[i].ia_status == 0) {
										apply_list_html += applyListHtml(studentApplicationList[i]);
									} else {
										apply_list_html += ""
									}
								}
								ul_enterprise_list.innerHTML = apply_list_html;
							} else {
								ul_enterprise_list.innerHTML = "";
							}
							
							//动态对不通过按钮进行事件绑定
							mui(".btnOper").on("tap", ".notPassRequest", function(e) {
								var iaId = this.getAttribute("iaId");
								examineApply(iaId, 2);
								app.showToast("已拒绝通过该学生的申请","success");
							});
							
							//动态对通过按钮进行事件绑定
							mui(".btnOper").on("tap", ".passRequest", function(e) {
								var iaId = this.getAttribute("iaId");
								var studentId = this.getAttribute("studentId");
								mui.ajax(app.serverUrl + "/user/teacher/cout_student_companyNumber?user_id=" + studentId , {
									data: {},
									dataType: 'json', //服务器返回json格式数据
									type: 'post', //HTTP请求类型
									timeout: 10000, //超时时间设置为10秒；
									headers: {
										'Content-Type': 'application/json'
									},
									success: function(data) {
										console.log(data.data);
										if (data.data < 1) {
											examineApply(iaId, 1);
											app.showToast("已通过该学生的申请","success");
										} else {
											app.showToast("该学生已经通过一家企业申请，操作无效！","error");
										}
									}
								});
								
							});
							
							
						} else {
							app.showToast("获取数据失败，请重试！", "error");
						}
					}
				});
				
			}

			// // 获取请求列表并存入缓存
			// function getApplyList() {
			// 	var teacher = app.getGlobalUserInfo();

			// 	mui.ajax(app.serverUrl + "/user/teacher/examine_online_apply_list?user_id=" + teacher.user_id, {
			// 		data: {},
			// 		dataType: 'json', //服务器返回json格式数据
			// 		type: 'post', //HTTP请求类型
			// 		timeout: 10000, //超时时间设置为10秒；
			// 		headers: {
			// 			'Content-Type': 'application/json'
			// 		},
			// 		success: function(data) {
			// 			if (data.status == 200) {
			// 				app.setOnlineApplyList(data.data)
			// 			} else {
			// 				app.showToast("获取数据失败，请重试！", "error");
			// 			}
			// 		}
			// 	});
			// }

			// 预约审批
			function examineApply(iaId, operType) {
				mui.ajax(app.serverUrl + "/user/teacher/examine_online_apply?ia_id=" + iaId + "&ia_status=" + operType, {
					data: {},
					dataType: 'json', //服务器返回json格式数据
					type: 'post', //HTTP请求类型
					timeout: 10000, //超时时间设置为10秒；
					headers: {
						'Content-Type': 'application/json'
					},
					success: function(data) {
						// app.deleteOnlineApplyList();
						// getApplyList();
						loadingOnlineApply();
					}
				});
			}

			// 学生申请预约公司的列表
			function applyListHtml(student) {
				var html = "";
				html = '<li class="btnOper mui-table-view-cell mui-media">' +
					'<a href="javascript:;">' +
					'<img class="mui-media-object mui-pull-left" src="' + app.imgServerUrl + student.head_portrait_url_small +
					'">' +
					'<span id="span_nickname" class="mui-pull-right">' +
					'<button studentId="' + student.ia_stu_id + '" iaId="' + student.ia_id + '" type="button" class="notPassRequest mui-btn mui-btn-danger"' +
					'style="padding: 4px 10px;margin-right: 5px;">不通过</button>' +
					'<button studentId="' + student.ia_stu_id + '" iaId="' + student.ia_id + '" type="button" class="passRequest mui-btn mui-btn-green"' +
					'style="padding: 4px 10px;">通过</button>' +
					'</span>' +
					'<div class="mui-media-body">' +
					'<label>学生:' + student.s_name + '</label>' +
					'<p class="mui-ellipsis">申请公司:' + student.e_name + '</p>' +
					'</div>' +
					'</a>' +
					'</li>';
				return html;
			}
		</script>
	</body>

</html>
